import Vue from 'vue'
import App from './App.vue'
import router from "./router";
import store from "./store";
import Moment from 'moment';
import VueLazyLoad from 'vue-lazyload'
import layer from "vue2-layer-mobile";
import {LOGIN_TOKEN, USER_INFO} from "@/common/constant";

Vue.config.productionTip = false
Vue.prototype.$bus = new Vue();

Vue.prototype.$moment = Moment;//赋值使用
Vue.filter('dateformat', function (dataStr, pattern = 'YYYY-MM-DD') {
    dataStr = !isNaN(dataStr) && dataStr.toString().length === 10 ? dataStr * 1000 : dataStr;
    return Moment(dataStr).format(pattern)
})
Vue.mixin({
        methods: {
            __uuid() {
                return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                    let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
                    return v.toString(16);
                });
            },
            __loginSuccess(phone, token) {
                if (token) {
                    localStorage.setItem(LOGIN_TOKEN, token);
                    localStorage.setItem(USER_INFO, JSON.stringify({phone}));
                }
            }
        }
    }
)
Vue.use(VueLazyLoad, {
    preLoad: 1,
    loading: require('@/assets/img/common/placeholder.png')
});
Vue.use(layer);

new Vue({
    render: h => h(App),
    router,
    store
}).$mount('#app')
